package com.xyebank.ledger.service.jryzadd.dataProvider.apply;

import com.xyebank.ledger.service.common.DataProvider;
import com.xyebank.ledger.vo.deal.ZADDJryCashApplyVo;

import org.junit.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class ZADDJryCashApplyProvider implements DataProvider<ZADDJryCashApplyVo> {

	@Autowired
	private ZADDJryCashApplyMapper ZADDJryCashApplyMapper;

	@Override
	public List<ZADDJryCashApplyVo> get(Integer fromIdx, Integer tarNum) {
		List<ZADDJryCashApply> result = ZADDJryCashApplyMapper.selectByPaging(fromIdx, tarNum);
		List<ZADDJryCashApplyVo> list = convert2Vo(result);
		return list;
	}

	@Override
	public List<ZADDJryCashApplyVo> get(Date dateStart, Date dateEnd, Integer fromIdx, Integer tarNum) {
		List<ZADDJryCashApply> result = ZADDJryCashApplyMapper.selectByPeriod(dateStart, dateEnd, fromIdx, tarNum);
		List<ZADDJryCashApplyVo> list = convert2Vo(result);
		return list;
	}

	@Override
	public Integer count(Date timeStart, Date timeEnd) {
		Integer count = ZADDJryCashApplyMapper.selectPeriodCount(timeStart, timeEnd);
		return count;
	}

	private List<ZADDJryCashApplyVo> convert2Vo(List<ZADDJryCashApply> result) {
		List<ZADDJryCashApplyVo> list = new ArrayList<ZADDJryCashApplyVo>();
		for (int i = 0; i < result.size(); i++) {
			ZADDJryCashApplyVo vo = new ZADDJryCashApplyVo();
			BeanUtils.copyProperties(result.get(i), vo);
			list.add(vo);
		}
		return list;
	}

	@Test
	public void ss() {
		List<ZADDJryCashApplyVo> list = get(0, 5);
		for (ZADDJryCashApplyVo zaddJryCashApplyVo : list) {
			System.out.println(zaddJryCashApplyVo.getd());
		}
	}

}
